#pragma once

#include "dsegen.h"
#include "FindNeighbor.h"

namespace dhis
{
	typedef std::hash_map<int,CRectI> RectMap;

	//----------------------------------------------------------------------------------
	class CBlockChessboard
	{
	public:
		CBlockChessboard(const int& w, const int& h, const int& div = 1024);
		virtual ~CBlockChessboard(void);
	public:
		inline int Width() const { return m_width; }
		inline int Height() const { return m_height; }
		inline int BlockWidth() const { return m_blockWidth; }
		inline int BlockHeight() const { return m_blockHeight; }
		inline int BlockRow() const { return m_blockRow; }
		inline int BlockCol() const { return m_blockCol; }

		inline int GetBlockCount() const { return m_rects.size(); }
		inline int GetBlockKey(const int& idx) const { return m_keys[idx]; }
		inline CRectI& GetBlockRect(const int& key) { return m_rects[key]; }
	public:
		bool IsBlockKey(const int& key) const;
		int   AtBlock(const int& row, const int& col) const;
		int   AtBlock(const int& id) const;
		inline int  GetBlockRow(const int& key) const { return (key/m_blockCol); }
		inline int  GetBlockCol(const int& key) const { return (key%m_blockCol); }
	private:
		int             m_width;
		int             m_height;
		int             m_blockWidth;
		int             m_blockHeight;
		int             m_blockRow;
		int             m_blockCol;
		IntVec       m_keys;
		RectMap   m_rects;
	};

}
